package ycl.system.service.impl;

import org.springframework.stereotype.Service;
import ycl.system.req.SysPermissionReq;
import ycl.common.base.service.impl.BaseServiceImpl;
import ycl.system.entity.SysPermission;
import ycl.system.mapper.SysPermissionMapper;
import ycl.system.mapper.SysUserMapper;
import ycl.system.res.SysPermissionRes;
import ycl.system.service.SysPermissionService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 权限 服务实现类
 * </p>
 *
 * @author ycl
 * @since 2022-03-03 11:43:56
 */
@Service
public class SysPermissionServiceImpl extends BaseServiceImpl
		<SysPermissionMapper, SysPermission, SysPermissionReq, SysPermissionRes>
		implements SysPermissionService {

	@Resource
	private SysPermissionMapper sysPermissionMapper;
	@Resource
	private SysUserMapper sysUserMapper;

	@Override
	public List<SysPermission> selectByUserId(Long userId) {
		Integer type = sysUserMapper.selectTypeById(userId);
		if (type == null)
			return new ArrayList<>();
		//超管拥有所有权限
		if (type == 0)
			return sysPermissionMapper.selectList(null);
		return sysPermissionMapper.selectByUserId(userId);
	}
}
